import java.util.Calendar;
import java.util.Date;

import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.FrameUtil;

public class Demo {

	public static void main(String[] args) {
		long ct = FrameUtil.getTime();
		for (int i = 0; i < 2500; i++) {
			System.out
					.println(showTime(DateUtil.timestampToDate(ct + i * 120)));

		}
		System.out.println(DateUtil.getTimeStempBetweenDay(FrameUtil.getTime(),
				FrameUtil.getTime() + 3600 * 24 - 1000));
	}

	/**
	 * 显示时间，如果与当前时间差别小于一天，则自动用**秒(分，小时，天)前
	 * 
	 * @author wxy
	 * @param ctime
	 *            时间
	 * @return
	 */
	public static String showTime(Date ctime) {
		String r = "";
		if (ctime == null)
			return r;

		long nowtimelong = System.currentTimeMillis();
		long ctimelong = ctime.getTime();
		long result = Math.abs(nowtimelong - ctimelong);

		if (result < 60000)// 一分钟内
		{
			long seconds = result / 1000;
			r = seconds + "秒钟前";
		} else if (result >= 60000 && result < 3600000)// 一小时内
		{
			long seconds = result / 60000;
			r = seconds + "分钟前";
		} else if (result >= 3600000 && result < 86400000)// 一天内
		{
			long seconds = result / 3600000;
			r = seconds + "小时前";
		} else// 日期格式
		{
			r = DateUtil.getBetweenDay(Calendar.getInstance().getTime(), ctime)
					+ "天之前";
		}
		return r;
	}
}
